package 尚硅谷.juc.test2;

import java.util.concurrent.TimeUnit;

public class Test2 {

    static boolean run = true;

    //锁对象
    final static Object object=new Object();

    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            while (true){
                synchronized (object){
                    if (!run){
                        break;
                    }
                }
            }
        },"BBB").start();
        TimeUnit.SECONDS.sleep(3);
        synchronized (object){
            run=false;
        }
        System.out.println("将共享变量run的值改成false");
    }
}
